home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / 2.0_nxyPalette1.2 / src / NXYView.m < prev    next >
Encoding:
Text File  |  1992-05-26  |  19.7 KB  |  704 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "NXYView.h"
  5. #import "Plot.h"
  6. #import "title.h"
  7. #import <appkit/appkit.h>    /* only for NXBeep */
  8. #import <appkit/graphics.h>
  9. #import <dpsclient/event.h>
  10. #import <appkit/Pasteboard.h>
  11.  
  12. @implementation NXYView
  13.  
  14. #ifndef MIN
  15. #define MIN(x,y) ((x)<(y)? (x) : (y))
  16. #endif
  17.  
  18. #ifndef MAX
  19. #define MAX(x,y) ((x)>(y)? (x) : (y))
  20. #endif
  21.  
  22. #ifndef ABS
  23. #define ABS(x) ( (x)<0? (-(x)) : (x) )
  24. #endif
  25.  
  26. #ifndef SGN
  27. #define SGN(x) ( (x)<0? -1.0 : 1.0 )
  28. #endif
  29.  
  30. #define XOFFSET 100.0        /* offsets (in pixels) of axis origin from */
  31. #define YOFFSET  50.0        /* lower left hand corner of window        */
  32.  
  33.  
  34. - (const char *)inspectorName
  35. {
  36.     return "NXYInspector";
  37. }
  38.  
  39. - (int)nPoints
  40. {
  41. //  if (drawingLegendLines)  return 2;
  42. //  else return 1;
  43. return 1;  //Added by cwf, no legends
  44. }
  45.  
  46.  
  47. - initPlot:sender
  48. {
  49. // const char * xtitle = [plotParam provideXtitle];
  50. char * xtitle = [self xaxisLabel];
  51. //   const char * ytitle = [plotParam provideYtitle];
  52. char * ytitle = [self yaxisLabel];
  53. //  const char * maintitle = [plotParam provideMaintitle];
  54. char * maintitle = [self mainTitle];
  55.   float   xwid;
  56.   id    axistitlefont, maintitlefont;
  57.   
  58.   [self clear:self];
  59.   PSsetlinewidth(0.0);
  60.   [self setDrawColor:NX_BLACK];
  61.   axistitlefont =
  62.     [Font newFont:"Helvetica" size:14.0 style:0 matrix:NX_IDENTITYMATRIX];
  63.   [axistitlefont set];
  64.   xwid = [axistitlefont getWidthOf:xtitle];
  65.   PSmoveto((bounds.size.width - xwid)/2.0, 10.0);
  66.   PSshow((char *)xtitle);
  67.   xwid = [axistitlefont getWidthOf:ytitle];
  68.   PSmoveto(20.0, (bounds.size.height - xwid)/2.0);
  69.   PSgsave();
  70.   PSrotate(90.0);
  71.   PSshow((char *)ytitle);
  72.   PSgrestore();
  73.   maintitlefont =
  74.     [Font newFont:"Helvetica" size:16.0 style:0 matrix:NX_IDENTITYMATRIX];
  75.   [maintitlefont set];
  76.   xwid = [maintitlefont getWidthOf:maintitle];
  77.   PSmoveto((bounds.size.width - xwid)/2.0, bounds.size.height - 20.0);
  78.   PSshow((char *)maintitle);
  79. //Finished title in initPlot method, starting to draw the box;
  80.   if ([plotParam shouldDrawBox]) {
  81.     PSsetlinewidth(4.0);
  82.     PSmoveto(0.0, 0.0);
  83.     PSlineto(bounds.size.width, 0.0);
  84.     PSlineto(bounds.size.width, bounds.size.height);
  85.     PSlineto(0.0, bounds.size.height);
  86.     PSlineto(0.0, 0.0);
  87.     PSstroke();
  88.     PSsetlinewidth(0.0);
  89.   }
  90.   return self;
  91. }
  92.  
  93. - setDrawColor:(float) color
  94. {
  95.   PSsetgray(color);
  96.   return self;
  97. }
  98.  
  99. - drawLines:sender :(BOOL)xaxislog :(BOOL)yaxislog
  100. /*
  101.  * This is coded so that when drawLines is called with plotParam as argument,
  102.  * it draws the data curves; when drawLines is called with self (plotView) as
  103.  * argument, it draws the short line segments in the legend box.
  104.  */
  105. {
  106.   int i,j;
  107.   NXCoord *x   = [sender xdata];
  108.   NXCoord **y  = [sender ydata];
  109.   int npoints  = [sender nPoints];
  110.   int ncurves  = [plotParam nCurves];
  111.   int linestyle;
  112.   float thick = 0.0;
  113.   float pattern0[] = {};    /* solid      */
  114.   float pattern1[] = {4.0, 4.0}; /* dash       */
  115.   float pattern2[] = {1.0, 3.0}; /* dot        */
  116.   float pattern3[] = {7.0, 3.0, 3.0, 3.0}; /* chain dash */
  117.   float pattern4[] = {7.0, 4.0, 1.0, 4.0}; /* chain dot  */
  118.  
  119.   switch([plotParam providelinethickness]){
  120.   case 0:
  121.     thick = 0.0;        /* thin lines : good for screen */
  122.     break;
  123.   case 1:
  124.     thick = 2.0;        /* medium lines */
  125.     break;
  126.   case 2:
  127.     thick = 3.0;        /* fat lines */
  128.     break;
  129.   }
  130.  
  131.   PSnewpath();
  132.   PSsetlinewidth(thick);
  133.   for (j=0; j<ncurves; j++) {
  134.     linestyle = [plotParam providelinestyle:j];
  135.     switch(linestyle) {
  136.     case 0:
  137.       PSsetdash(pattern0, 0, 0.0);
  138.       break;
  139.     case 1:
  140.       PSsetdash(pattern1, 2, 0.0);
  141.       break;
  142.     case 2:
  143.       PSsetdash(pattern2, 2, 0.0);
  144.       break;
  145.     case 3:
  146.       PSsetdash(pattern3, 4, 0.0);
  147.       break;
  148.     case 4:
  149.       PSsetdash(pattern4, 4, 0.0);
  150.       break;
  151.     case 5:            /* no lines */
  152.       continue;
  153.     }
  154.     if (linestyle == N_LINE_STYLES-1) continue;    /* no lines, go to next curve */
  155.     if (!xaxislog && !yaxislog) {
  156.       PSmoveto(x[0]*ppxunit, *(*(y + j)) * ppyunit );
  157.       for (i=1; i<npoints; i++) {
  158.     if ( (i % 512) == 0 ) {
  159.       PSstroke();
  160.       PSnewpath();
  161.       PSmoveto(x[i-1]*ppxunit, *(*(y+j)+i-1) * ppyunit);
  162.     }
  163.     PSlineto(x[i]*ppxunit, *(*(y+j)+i) * ppyunit);
  164.       }
  165.       PSstroke();
  166.     }
  167.     else if (!xaxislog && yaxislog) {
  168.       PSmoveto(x[0]*ppxunit, (float)log10((double)*(*(y + j))) * ppyunit );
  169.       for (i=1; i<npoints; i++) {
  170.     if ( (i % 512) == 0 ) {
  171.       PSstroke();
  172.       PSnewpath();
  173.       PSmoveto(x[i-1]*ppxunit, (float)log10((double)*(*(y+j)+i-1)) * ppyunit);
  174.     }
  175.     PSlineto(x[i]*ppxunit, (float)log10((double)*(*(y+j)+i)) * ppyunit);
  176.       }
  177.       PSstroke();
  178.     }
  179.     else if (xaxislog && !yaxislog) {
  180.       PSmoveto((float)log10((double)x[0])*ppxunit, *(*(y + j)) * ppyunit );
  181.       for (i=1; i<npoints; i++) {
  182.     if ( (i % 512) == 0 ) {
  183.       PSstroke();
  184.       PSnewpath();
  185.       PSmoveto((float)log10((double)x[i-1])*ppxunit,*(*(y+j)+i-1) * ppyunit);
  186.     }
  187.     PSlineto((float)log10((double)x[i])*ppxunit, *(*(y+j)+i) * ppyunit);
  188.       }
  189.       PSstroke();
  190.     }
  191.     else if (xaxislog && yaxislog) {
  192.       PSmoveto((float)log10((double)x[0])*ppxunit,
  193.            (float)log10((double)*(*(y + j))) * ppyunit );
  194.       for (i=1; i<npoints; i++) {
  195.     if ( (i % 512) == 0 ) {
  196.       PSstroke();
  197.       PSnewpath();
  198.       PSmoveto((float)log10((double)x[i-1])*ppxunit,
  199.            (float)log10((double)*(*(y+j)+i-1)) * ppyunit);
  200.     }
  201.     PSlineto((float)log10((double)x[i])*ppxunit,
  202.          (float)log10((double)*(*(y+j)+i)) * ppyunit);
  203.       }
  204.       PSstroke();
  205.     }
  206.   }
  207.   PSsetdash(pattern0, 0, 0.0);    /* back to solid lines  */
  208.   return self;
  209. }
  210.  
  211. #define SQRT3  1.73205081
  212. /*
  213.  * We had an elegant idea for drawing the symbols: draw each symbol just once
  214.  * in an off-screen window, then composite them in where needed.  This worked
  215.  * fine for screen drawing (modulo a little difficulty in compositing to just
  216.  * the right spot), but was a miserable failure when it came to printing: the
  217.  * print machinery scaled the composite bitmap.  We finally decided to abandon
  218.  * compositing, in the interest of keeping our screen drawing code the same as
  219.  * our printing code.
  220.  */
  221.  
  222.  
  223. - clear:sender
  224. {
  225.   NXEraseRect(&bounds);
  226.   return self;
  227. }
  228.  
  229. - clearNXYView:sender
  230. {
  231.     [self setXminValue:0.0];
  232.     [self setXmaxValue:0.0];
  233.     [self setYminValue:0.0];
  234.     [self setYmaxValue:0.0];
  235.     [self display];            
  236.   return self;
  237. }
  238.  
  239. - drawTicMarks:(float)xmin :(float)xmax :(float)ymin :(float)ymax
  240. {
  241.   float pattern0[] = {};    /* solid      */
  242.   float pattern2[] = {1.0, 3.0}; /* dot        */
  243.   float xinc = [plotParam provideXinc] * ppxunit;
  244.   float yinc = [plotParam provideYinc] * ppyunit;
  245.   char ticlabel[32];
  246.   id ticfont;
  247.   float x, y;
  248.   BOOL drawGrid = [plotParam shouldDrawGrid];
  249.   BOOL xaxislog = [plotParam xaxisLog];
  250.   BOOL yaxislog = [plotParam yaxisLog];
  251.   int  nmin, nmax, j, i;
  252.   float ticloc;
  253.  
  254.   /* get tic font initialized */
  255.   ticfont = [Font newFont:"Helvetica" size:10.0 style:0 matrix:NX_IDENTITYMATRIX];
  256.   [ticfont set];
  257.  
  258.   PSnewpath();
  259.   PSsetlinewidth(0.0);
  260.   if (xaxislog) {
  261.     nmin = (int)floor((double)(xmin/ppxunit));
  262.     nmax = (int)ceil((double)(xmax/ppxunit));
  263.     for (j=nmin; j<=nmax; j++) {
  264.       if ( (float)j * ppxunit > xmin &&  (float)j * ppxunit < xmax ) {
  265.     if (drawGrid) {
  266.       PSmoveto((float)j * ppxunit, ymin);
  267.       PSsetdash(pattern2, 2, 0.0);
  268.       PSrlineto(0.0, ABS(ymax-ymin));
  269.       PSstroke();
  270.     }
  271.     PSmoveto((float)j * ppxunit, ymin - 6.0); /* big tic mark */
  272.     PSsetdash(pattern0, 0, 0.0);
  273.     PSrlineto(0.0, 6.0);
  274.     PSstroke();
  275.     PSmoveto((float)j * ppxunit - 8.0, ymin - 20.0);
  276.     PSshow("10");
  277.     PSmoveto((float)j * ppxunit + 2.0, ymin - 14.0);
  278.     sprintf(ticlabel, "%-5d", j);
  279.     PSshow(ticlabel);
  280.       }
  281.       for (i=2; i<=9; i++) {
  282.     ticloc = (float)j * ppxunit + ppxunit*(float)log10((double)i);
  283.     if ( ticloc>xmin && ticloc<xmax ) {
  284.       PSmoveto(ticloc, ymin - 4.0);    /* small tic mark */
  285.       PSrlineto(0.0, 4.0);
  286.       PSstroke();
  287.     }
  288.       }
  289.     }
  290.   }
  291.   else {
  292.     if (xinc*(xmax-xmin) < 0.0) { /* the bad case - avoid infinite loop! */
  293.       xinc = -xinc;
  294.       [plotParam resetXinc:xinc/ppxunit];
  295.     }
  296.     x = xmin;
  297.     while (SGN(xmax-x) == SGN(xmax-xmin)) {
  298.       if (drawGrid) {
  299.     PSmoveto(x, ymin);
  300.     PSsetdash(pattern2, 2, 0.0);
  301.     PSrlineto(0.0, ABS(ymax-ymin));
  302.     PSstroke();
  303.       }
  304.       PSmoveto(x, ymin - 4.0);
  305.       PSsetdash(pattern0, 0, 0.0);
  306.       PSrlineto(0.0, 4.0);
  307.       PSstroke();
  308.       sprintf(ticlabel, "%6.2g", x/ppxunit);
  309.       PSmoveto(x - 14.0, ymin - 14.0);
  310.       PSshow(ticlabel);
  311.       x += xinc;
  312.     }
  313.   }
  314.   if (yaxislog) {
  315.     nmin = (int)floor((double)(ymin/ppyunit));
  316.     nmax = (int)ceil((double)(ymax/ppyunit));
  317.     for (j=nmin; j<=nmax; j++) {
  318.       if ( (float)j * ppyunit > ymin &&  (float)j * ppyunit < ymax ) {
  319.     if (drawGrid) {
  320.       PSmoveto(xmin, (float)j * ppyunit);
  321.       PSsetdash(pattern2, 2, 0.0);
  322.       PSrlineto(ABS(xmax-xmin), 0.0);
  323.       PSstroke();
  324.     }
  325.     PSmoveto(xmin - 6.0, (float)j * ppyunit); /* big tic mark */
  326.     PSsetdash(pattern0, 0, 0.0);
  327.     PSrlineto(6.0, 0.0);
  328.     PSstroke();
  329.     PSmoveto(xmin - 30.0, (float)j * ppyunit - 6.0);
  330.     PSshow("10");
  331.     PSmoveto(xmin - 20.0, (float)j * ppyunit - 1.0);
  332.     sprintf(ticlabel, "%-5d", j);
  333.     PSshow(ticlabel);
  334.       }
  335.       for (i=2; i<=9; i++) {
  336.     ticloc = (float)j * ppyunit + ppyunit*(float)log10((double)i);
  337.     if (ticloc>ymin && ticloc<ymax) {
  338.       PSmoveto(xmin - 4.0, ticloc); /* small tic mark */
  339.       PSrlineto(4.0, 0.0);
  340.       PSstroke();
  341.     }
  342.       }
  343.     }
  344.   }
  345.   else {
  346.     if (yinc*(ymax-ymin) < 0.0) { /* the bad case - avoid infinite loop! */
  347.       yinc = -yinc;
  348.       [plotParam resetYinc:yinc/ppyunit];
  349.     }
  350.     y = ymin;
  351.     while (SGN(ymax-y) == SGN(ymax-ymin)) {
  352.       if (drawGrid) {
  353.     PSmoveto(xmin, y);
  354.     PSsetdash(pattern2, 2, 0.0);
  355.     PSrlineto(ABS(xmax-xmin), 0.0);
  356.     PSstroke();
  357.       }
  358.       PSmoveto(xmin - 4.0, y);
  359.       PSsetdash(pattern0, 0, 0.0);
  360.       PSrlineto(4.0, 0.0);
  361.       PSstroke();
  362.       sprintf(ticlabel, "%6.2g", y/ppyunit);
  363.       PSmoveto(xmin - 40.0, y - 4.0);
  364.       PSshow(ticlabel);
  365.       y += yinc;
  366.     }
  367.   }
  368.   return self;
  369. }
  370.  
  371. - initFrame:(NXRect *)frameRect
  372. {
  373.     self = [super initFrame:frameRect];
  374.     [self setBorder:YES];
  375.     [self setGrid:NO];
  376.     [self setAutoMaxMinState:YES];
  377.     [self setAutoPaperState:YES];
  378.     [self setPaperSwitchRow:4];   // Set the "paper Type" to auto on switch
  379.     [self setLogoFlag:YES];
  380.  
  381.     mainTitle = "Main Title";
  382.     xaxisLabel = "x axis";
  383.     yaxisLabel = "y axis";
  384.         
  385. return self;
  386. }
  387.  
  388.  
  389. - drawSelf: (const NXRect *)rects :(int)rectCount
  390. {
  391.   float  xmin = [plotParam provideXmin];
  392.   float  xmax = [plotParam provideXmax];
  393.   float  ymin = [plotParam provideYmin];
  394.   float  ymax = [plotParam provideYmax];
  395.   float xscale,yscale;
  396.   NXRect framerect;
  397.   
  398.     [self initPlot:self];
  399.  
  400.     if(strcmp([NXApp appName] , "InterfaceBuilder") ==0 && [self logoFlag] == YES){
  401.     [self getFrame:&framerect];
  402.  
  403.     xscale = framerect.size.width/500.0;
  404.     yscale = framerect.size.height/300.0;
  405.     
  406.             PSWTestTitle(xscale, yscale);
  407.     }
  408.  
  409.   if (!( (xmin == 0.0 && xmax== 0.0)  || (ymin== 0.0 && ymax == 0.0) )) {
  410.     PSgsave();
  411.  
  412.     PStranslate(XOFFSET, YOFFSET);
  413.     if ([plotParam xaxisLog]) {    /* x-axis is logarithmic */
  414.       if (xmin <= 0.0  ||  xmax <= 0.0) {
  415.     /* ring bells, fire rockets -- a voice alert would be nice */
  416.     [plotParam forceXaxisLinear]; /* force linear axis */
  417.     NXBeep();              /* here's the alert  */
  418.     ppxunit = 0.9*(bounds.size.width-XOFFSET)/(xmax-xmin);
  419.     xmin = xmin*ppxunit;        /* drawing is all in pixel coordinates */
  420.     xmax = xmax*ppxunit;
  421.       }
  422.       else {    
  423.     ppxunit = 0.9*(bounds.size.width-XOFFSET)/(float)log10((double)(xmax/xmin));
  424.     xmin = (float)log10((double)xmin) * ppxunit;
  425.     xmax = (float)log10((double)xmax) * ppxunit;
  426.       }
  427.     }
  428.     else {            /* x-axis is linear */
  429.       ppxunit = 0.9*(bounds.size.width-XOFFSET)/(xmax-xmin);
  430.       xmin = xmin*ppxunit;        /* drawing is all in pixel coordinates */
  431.       xmax = xmax*ppxunit;
  432.     }
  433.     if ([plotParam yaxisLog]) {    /* y-axis is logarithmic */
  434.       if (ymin <= 0.0  ||  ymax <= 0.0) {
  435.     [plotParam forceYaxisLinear]; /* again should alert user */
  436.     NXBeep();              /* here's the (mild) alert */
  437.     ppyunit = 0.9*(bounds.size.height-YOFFSET)/(ymax-ymin);
  438.     ymin = ymin*ppyunit;
  439.     ymax = ymax*ppyunit;
  440.       }
  441.       else {
  442.     ppyunit = 0.9*(bounds.size.height-YOFFSET)
  443.                                 /(float)log10((double)(ymax/ymin));
  444.     ymin = (float)log10((double)ymin) * ppyunit;
  445.     ymax = (float)log10((double)ymax) * ppyunit;
  446.       }
  447.     }
  448.     else {            /* y-axis is linear */
  449.       ppyunit = 0.9*(bounds.size.height-YOFFSET)/(ymax-ymin);
  450.       ymin = ymin*ppyunit;
  451.       ymax = ymax*ppyunit;
  452.     }
  453.     PStranslate(-xmin, -ymin);
  454.     PSnewpath();        /* draw axes */
  455.     PSmoveto(xmin, ymin);
  456.     PSlineto(xmax,ymin);
  457.     PSlineto(xmax,ymax);
  458.     PSlineto(xmin,ymax);
  459.     PSclosepath();
  460.     PSstroke();            /* finish axes */
  461.  
  462.     [self drawTicMarks:xmin :xmax :ymin :ymax]; /* do this before clipping */
  463.  
  464.     /* MIN and MAX below in case xmin > xmax  and/or  ymin > ymax. */
  465.     PSrectclip(MIN(xmin,xmax), MIN(ymin,ymax), ABS(xmax-xmin), ABS(ymax-ymin));
  466.     [self drawLines:plotParam :[plotParam xaxisLog] :[plotParam yaxisLog]];
  467. //    [self drawSymbols:plotParam :[plotParam xaxisLog] :[plotParam yaxisLog]];
  468.  
  469.     PSgrestore();
  470. //    if ([plotParam shouldDrawLegend]) {
  471. //      [self initLegend:self];
  472. //      [self drawLegend:self];
  473. //    }
  474.   }
  475.  
  476.   return self;
  477. }
  478.  
  479. - doPrinting:sender
  480. {
  481.  
  482.   [ [NXApp printInfo] setMarginLeft:72.0 right:72.0 top:72.0 bottom:72.0 ];
  483.  
  484.   if (bounds.size.height > bounds.size.width) { /* portrait mode */
  485.     if (bounds.size.height/bounds.size.width > 9.0/6.5) {
  486.       [ [NXApp printInfo] setScalingFactor: 9.0*72.0/bounds.size.height];
  487.     }
  488.     else {
  489.       [ [NXApp printInfo] setScalingFactor: 6.5*72.0/bounds.size.width];
  490.     }
  491.     [ [NXApp printInfo] setOrientation:NX_PORTRAIT andAdjust:YES ];
  492.   }
  493.   else {            /* landscape mode */
  494.     if (bounds.size.width/bounds.size.height > 9.0/6.5) {
  495.       [ [NXApp printInfo] setScalingFactor: 9.0*72.0/bounds.size.width];
  496.     }
  497.     else {
  498.       [ [NXApp printInfo] setScalingFactor: 6.5*72.0/bounds.size.height];
  499.     }
  500.     [ [NXApp printInfo] setOrientation:NX_LANDSCAPE andAdjust:YES ];
  501.   }
  502.  
  503.   [self printPSCode:sender];
  504.   return self;
  505. }
  506.  
  507.  
  508. ////The following methods added by Charlie to get values from the Inspector. 
  509. // This is not the way I wanted to do it--I would rather have an additional inspector
  510. // that goes with the view (palette) when it is loaded into an App, but this won't go through
  511. // IB. The following is somewhat long-winded, the keeps the spirit of reading the value
  512. // from a controller panel. A shorter way would be to rewrite the nxyplot methods and
  513. // get values directly from the IB Inspector.
  514.  
  515.  -setGrid:(int)grid_state{gridState=grid_state; return self;}
  516. - setBorder:(int)border_state{ borderState=border_state; return self;}
  517. -(int)gridState{return gridState; }
  518. -(int)borderState{ return borderState;}
  519. -setAutoMaxMinState:(int)state{autoMaxMinState=state; return self;}
  520. -(int)autoMaxMinState{return autoMaxMinState;}
  521.  
  522. -setAutoPaperState:(int)state{autoPaperState=state; return self;}
  523. -(int)autoPaperState{return autoPaperState;}
  524. -setXLinLogState:(int)state{xLinLogState=state; return self;}
  525. -(int)xLinLogState{return xLinLogState;}
  526. -setYLinLogState:(int)state{yLinLogState=state; return self;}
  527. -(int)yLinLogState{return yLinLogState;}
  528. -setPaperSwitchRow:(int)state{paperSwitchRow=state; return self;}
  529. -(int)paperSwitchRow{return paperSwitchRow;}
  530. -setLogoFlag:(int)state{logoFlag=state; return self;}
  531. -(int)logoFlag{return logoFlag;}
  532.  
  533. -setMainTitle:(char *)mainTITLE{
  534.     if(mainTitle != 0) free(mainTitle);
  535.     mainTitle = malloc(strlen(mainTITLE)+1);
  536.     strcpy(mainTitle,mainTITLE); 
  537.     return self;}
  538. -setXaxisLabel:(char *)xAxisLabel{
  539.     if(xaxisLabel != 0) free(xaxisLabel);
  540.     xaxisLabel = malloc(strlen(xAxisLabel)+1);
  541.     strcpy(xaxisLabel, xAxisLabel); 
  542.     return self;}
  543. -setYaxisLabel:(char *)yAxisLabel{
  544.     if(yaxisLabel != 0) free(yaxisLabel);
  545.     yaxisLabel = malloc(strlen(yAxisLabel)+1);
  546.     strcpy(yaxisLabel, yAxisLabel); 
  547.     return self;}
  548. -(char *)mainTitle{return mainTitle;}
  549. -(char *)xaxisLabel{return xaxisLabel;}
  550. -(char *)yaxisLabel{return yaxisLabel;}
  551.  
  552. -setXincValue:(float)passedValue{xInc = passedValue; return self;}
  553. -setXminValue:(float)passedValue{xMin = passedValue; return self;}
  554. -setXmaxValue:(float)passedValue{xMax = passedValue; return self;}
  555. -setYincValue:(float)passedValue{yInc = passedValue; return self;}
  556. -setYminValue:(float)passedValue{yMin = passedValue; return self;}
  557. -setYmaxValue:(float)passedValue{yMax= passedValue; return self;}
  558. -(float)xIncValue{return xInc;}
  559. -(float)xMinValue{return xMin;}
  560. -(float)xMaxValue{return xMax;}
  561. -(float)yIncValue{return yInc;}
  562. -(float)yMinValue{return yMin;}
  563. -(float)yMaxValue{return yMax;}
  564.  
  565. // For testing -- open data file via right mouse click...
  566. - rightMouseDown:(NXEvent *)theEvent
  567. {
  568. // The following allows the uses to call up a file using the right mouse button when in
  569. // the test mode of IB. My thanks to Alex Cone of OTI for tips used to write this.
  570. // Note however that this will not work if there is a custom IB.
  571.     if(strcmp([NXApp appName] , "InterfaceBuilder") ==0){
  572.         [plotParam open:self];
  573.         return self;
  574.     }
  575.     else{
  576.         return self;
  577.     }
  578. }
  579.  
  580. -plotDataFromStream:sender
  581. {
  582. NXStream *dataStream;
  583.  
  584.     if(delegate && [delegate respondsTo:@selector(nxyView:provideDataStream:)])
  585.     {    [delegate  nxyView:self provideDataStream:&dataStream];
  586.     [plotParam useDataStreamAndPlot:dataStream];
  587.     }
  588.     else
  589.     { if(NXRunAlertPanel("Delegate", "No data stream avaliable to plot.",
  590.      "Continue", "Open Data File", NULL) == NX_ALERTALTERNATE){
  591.          [plotParam open:self];
  592.         return self;
  593.         }
  594.     return self;
  595.     }
  596.     return self;
  597. }
  598.  
  599. -setDelegate:anObject
  600. {
  601.     delegate = anObject;
  602.     return self;
  603. }
  604.  
  605. - setInspector:anObject
  606. {
  607.     inspector = anObject;
  608.     return self;
  609. }    
  610.  
  611. //// End Charlie's added metods......
  612.  
  613. // Following methods (saveEPS, savePSCode) taken from nxyplot1.7
  614. - saveEPS:sender
  615. {
  616.   id savePanel = [[SavePanel new] setRequiredFileType:"eps"];
  617.   char  *eps_fileName;    // Name of the EPS file for output
  618.  
  619.   if ([savePanel runModal])  {
  620.     eps_fileName = (char *) calloc(strlen([savePanel filename])+1, sizeof(char));
  621.     strcpy(eps_fileName, [savePanel filename]);
  622.     [self savePSCode:eps_fileName];
  623.   }
  624.  
  625.   return self;
  626. }
  627.  
  628. - savePSCode:(char *)aFile
  629. {
  630.     NXStream    *psStream;
  631.  
  632.     psStream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
  633.     if (!psStream)  {
  634.       return self;
  635.     }
  636.     [self getBounds:&bounds];
  637.     [self copyPSCodeInside:&bounds to:psStream];
  638.        
  639.     NXFlush(psStream);
  640.     NXSaveToFile(psStream, aFile);
  641.     NXCloseMemory(psStream, NX_FREEBUFFER);
  642.  
  643.     return self;
  644. }
  645.  
  646. // Following taken from the Concepts manual page 10-33
  647. -copyToPasteboard:sender
  648. {
  649.     id pb = [Pasteboard new];
  650.     NXStream *stream;
  651.     char *data;    
  652.     int length;
  653.     int maxLength;
  654.     
  655.     [pb declareTypes: &NXPostScriptPboard num:1 owner:self];
  656.     stream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
  657.      if (!stream)  {
  658.           return self;
  659.            }
  660.   
  661.         [self getBounds:&bounds];
  662.         [self copyPSCodeInside:&bounds to:stream];
  663.       NXGetMemoryBuffer(stream, &data, &length, &maxLength);
  664.       [pb writeType:NXPostScriptPboard data:data length:length];
  665.       NXCloseMemory(stream, NX_FREEBUFFER);
  666.        
  667.     return self;
  668. }
  669.  
  670. - read:(NXTypedStream*)stream
  671. /*
  672.  * Unarchives the  View.  Initializes four of the  View's instance variables
  673.  * to the values stored in the stream. 
  674.  */
  675. {    
  676.     [super read:stream];
  677.     delegate = NXReadObject(stream);
  678.     NXReadTypes(stream, "@ff", &plotParam, &ppxunit, &ppyunit);
  679.     NXReadTypes(stream,"iii",&gridState,&borderState,&autoMaxMinState);
  680.     NXReadTypes(stream,"***",&mainTitle,&xaxisLabel,&yaxisLabel);
  681.     NXReadTypes(stream,"ffffff",&xInc,&xMin,&xMax,&yInc,&yMin,&yMax);
  682.     NXReadTypes(stream,"iiiii",&autoPaperState,&xLinLogState,
  683.     &yLinLogState,&paperSwitchRow,&logoFlag);
  684.     return self;
  685. }
  686.  
  687. - write:(NXTypedStream*)stream
  688. /*
  689.  * Archives the  View by writing its important instance variables to the stream. 
  690.  */
  691. {
  692.     [super write:stream];
  693.     NXWriteObjectReference(stream, delegate);
  694.     NXWriteTypes(stream, "@ff", &plotParam, &ppxunit, &ppyunit);
  695.     NXWriteTypes(stream,"iii",&gridState,&borderState,&autoMaxMinState);
  696.     NXWriteTypes(stream,"***",&mainTitle,&xaxisLabel,&yaxisLabel);
  697.     NXWriteTypes(stream,"ffffff",&xInc,&xMin,&xMax,&yInc,&yMin,&yMax);
  698.     NXWriteTypes(stream,"iiiii",&autoPaperState,&xLinLogState,
  699.     &yLinLogState, &paperSwitchRow,&logoFlag);
  700.     return self;
  701. }
  702.  
  703. @end
  704.